package xyf.p01.array_nodelist;

import commons.ListNode;

/**
 * ClassName: P0328_OddEvenList
 * Description:
 * Author: xyf
 * Date: 9/7/22 7:42 PM
 * Version: 1.0
 **/
public class P0328_OddEvenList
{
    public ListNode oddEvenList(ListNode head)
    {
        if (head == null)
        {
            return null;
        }
        ListNode evenHead = head.next;
        ListNode odd = head;
        ListNode even = evenHead;

        while (even != null && even.next != null)
        {
            odd.next = even.next;
            even.next = even.next.next;

            odd = odd.next;
            even = even.next;
        }

        odd.next = evenHead;

        return head;
    }
}
